package cn.lucky.springcloud.service;

import cn.lucky.springcloud.client.OpenfeignHystrixClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;

/**
 * @author lingpeng.jiang
 * @create 2020-12-27-15:49
 */
@Service
public class HystrixOrderFeignService {


    @Resource
    private OpenfeignHystrixClient openfeignHystrixClient;

    public String hystrixPaymentInfo_OK(Integer id){
        return openfeignHystrixClient.hystrixPaymentInfo_OK(id);
    }

    @HystrixCommand(fallbackMethod = "hystrixPaymentInfo_TimeoutHandle",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "5000")
    })
    public String hystrixPaymentInfo_Timeout(Integer id){
        return openfeignHystrixClient.hystrixPaymentInfo_Timeout(id);
    }

    public String hystrixPaymentInfo_TimeoutHandle(Integer id){
        return "线程池: " + Thread.currentThread().getName() + " hystrixPaymentInfo_TimeoutHandle,消费者80,报错了";
    }


    public String circuitBreaker(Integer id){
        return openfeignHystrixClient.circuitBreaker(id);
    }

    public String getServerPort(){
        return openfeignHystrixClient.getServerPort();
    }

}
